package com.cnblog.blog.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class StringUtil {
	
	public static String inputStream2String(InputStream stream, String charset) throws UnsupportedEncodingException {
		InputStreamReader reader = new InputStreamReader(stream,charset);
		BufferedReader buffer = new BufferedReader(reader);
		StringBuilder sb = new StringBuilder();
		String cur;
		try {
			while((cur = buffer.readLine()) != null) {
				sb.append(cur);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			stream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}
	
	public static boolean matcher(String s, String pattern) {
		Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE);
		Matcher matcher = p.matcher(s);
		if(matcher.find()) {
			return true;
		} else {
			return false;
		}
	}
}
